package br.com.werp.regras.geral.integracao;

import br.com.werp.regras.geral.util.Constantes;
import br.com.werp.regras.geral.vos.tabelas.Lote;

import java.sql.Connection;

import java.util.List;
import java.util.ResourceBundle;

/**
 * @author Sobreira
 * Criado em 16/05/2005
 *
 */
public class LoteDAO extends MasterDAO {
    private static LoteDAO loteDAO;
	
    private LoteDAO(String banco) throws Exception {
        super(banco);
    }
    
    public static LoteDAO getLoteDAO() throws Exception {
        if (loteDAO == null) {
            ResourceBundle bundle = ResourceBundle.getBundle(Constantes.CONFIG);
            loteDAO = new LoteDAO(bundle.getString(Constantes.BANCO));
        }

        return loteDAO;
    }

    public Lote obterLote(String LoteId) throws Exception {
        return obterLote(getConexao(), LoteId);
    }

    public Lote obterLote(Connection conexao, String LoteId)
        throws Exception {
        Connection conn = null;
        try {
            conn = (Connection) conexao;

            List l = preencheVO(conn, new Lote(), " lote_id = " + LoteId);
            if (l.isEmpty())
                return null;

            return (Lote) l.get(0);
        } catch (Exception e) {
            throw e;
        } finally {
            if (conn.getAutoCommit())
                liberaConeccao(conn);
        }
    }
}
